# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：merge_line.py
#日期：2021-03-08
#备注：非断句行内容进行合并
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
from pycacho.cachobase.file_deal import a_save_txt,an_save_txt,ann_save_txt

last_word = ['」','。','＊','！','…','１','=','.','？','”','*','－','-',
             'x','）','~','章','～','）','e','！','”','】','.','i','代',']','」']
n_word = ['）']      # 两行
m_word = '章 '  # 分段
p_word = '？”'
st_word = '    '

# 合并不完整的行
def get_lines(file,new_file):
    with open(file, "r", encoding='utf-8') as fp:
        for line1 in fp.readlines():
            line = line1.strip()
            #print(line[-1:])     #倒数第一个
            #print(line[-2:-1])   倒数第二个
            if m_word in line:
                new_line = line
                print(new_line)
                ann_save_txt(new_file,new_line)
            elif line[-1:] in last_word:
                new_line = line.strip()
                an_save_txt(new_file,new_line)
            else:
                new_line = line.strip()
                a_save_txt(new_file,new_line)


def split_part(file,new_file):
    with open(file, "r", encoding='utf-8') as fp:
        for line in fp.readlines():
            if p_word in line:
                info = line.rstrip().split(p_word)
                if info[-1:] == ['']:
                    temp = info[:-1]
                    print(temp)
                else:
                    temp = info
                for i in temp:
                    an_save_txt(new_file, i+p_word)
            else:
                an_save_txt(new_file, line)

def start_lines(file,new_file):
    with open(file, "r", encoding='utf-8') as fp:
        for line in fp.readlines():
            if line[0:4] in st_word:
                new_line = line.strip()
                an_save_txt(new_file,new_line)
            elif line[-2:-1] in n_word:
                new_line = line.rstrip()
                print(new_line)
                ann_save_txt(new_file,new_line)
            elif m_word in line:
                new_line = line
                print(new_line)
                ann_save_txt(new_file,new_line)
            else:
                new_line = line.strip()
                a_save_txt(new_file,new_line)


if __name__ == '__main__':
    get_lines('F:\PythonProject\python\\da30.txt','F:\PythonProject\python\\temp.txt')
    #split_part('F:\PythonProject\python\\wx3.txt', 'F:\PythonProject\python\\wx4.txt')
